package nl.renedegroot.android.intervalbeeper;

import java.util.Timer;

import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.util.Log;

public class SoundTimerless extends SoundTimer
{
   private static final String TAG = SoundTimerless.class.getCanonicalName();

   SoundTimerless(Context context, int soundId, String soundName)
   {
      super( context, soundName, -1l, -1l );
      mSoundId = soundId;
   }
   
   SoundTimerless(Context context, Uri fileUri, String soundName)
   {
      super( context, soundName, -1l, -1l );
      mFileUri = fileUri;
   }
   
   public void scheduleYourselfAtFixedRate( Timer timer )
   {
      if( mFileUri != null )
      {
         mMediaPlayer = MediaPlayer.create( mContext, mFileUri );
      }
      else 
      {
         mMediaPlayer = MediaPlayer.create( mContext, mSoundId );

      }
      Log.d( TAG, "Task#run()" );
      mMediaPlayer.seekTo( 0 );
      mMediaPlayer.start();
   }
   
   public void cancel()
   {
      if( mMediaPlayer != null )
      {
         mMediaPlayer.release();
      }
   }
   
   @Override
   public String toString()
   {
      return String.format( "Play %s once", mSoundname  );
   }
}
